﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UT_AMS.DataAccess.BO;
using AMS.DataAccess.Sql;

namespace UT_AMS.DataAccess
{
    /// <summary>
    /// Summary description for UT_SqlInsert
    /// </summary>
    [TestClass]
    public class UT_SqlBuilder_Compact
    {
        public UT_SqlBuilder_Compact()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestBasic()
        {
            SqlBuilder sql = new SqlBuilder();
            sql.Add("SELECT");
            sql.Add("AID, Name, Birthday");
            sql.Add("FROM RealUserTable");
            sql.Add("WHERE 1=1");

            string ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") >= 0);

            sql = new SqlBuilder(true);
            sql.Add("SELECT");
            sql.Add("AID, Name, Birthday");
            sql.Add("FROM RealUserTable");
            sql.Add("WHERE 1=1");

            ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf(" SELECT") < 0);
            Assert.IsTrue(ssql.IndexOf("\r\n") < 0);

            sql = new SqlBuilder();
            sql.CompactMode = true;
            sql.Add("SELECT");
            sql.Add("AID, Name, Birthday");
            sql.Add("FROM RealUserTable");
            sql.Add("WHERE 1=1");

            ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") < 0);


            sql = new SqlBuilder();
            sql.Add("SELECT");
            sql.Add("AID, Name, Birthday");
            sql.Add("FROM RealUserTable");
            sql.Add("WHERE 1=1");
            sql.CompactMode = true;

            ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") >= 0);
        }

        [TestMethod]
        public void Test_语句开头包含空格()
        {

            var sql = new SqlBuilder(true);
            sql.Add("SELECT");
            sql.Add(" AID, Name, Birthday");
            sql.Add("	FROM RealUserTable");
            sql.Add(" WHERE 1=1");

            var ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf(" WHERE") >= 0);
            Assert.IsTrue(ssql.IndexOf("  WHERE") < 0);
            Assert.IsTrue(ssql.IndexOf("	FROM") >= 0);
            Assert.IsTrue(ssql.IndexOf(" 	FROM") < 0);
        }

    }
}
